

'''
array = np.array([[1,2,3],
                  [2,3,4]])

print(array)
print('number of dim',array.ndim)
print('shape:',array.shape)
print('size:',array.size)
'''
'''
import numpy as np

a = np.array([[10,20],
              [30,40]])
b = np.arange(4).reshape((2,2))

print(a)
print(b)

c = a*b
c_dot = np.dot(a,b)
c_dot_2=a.dot(b)

print(c)
print(c_dot)
print(c_dot_2)
# print(b<3)
# print(c.dtype)
'''
'''
import numpy as np

a = np.random.random((3,4))

print(a)
print(np.sum(a))
print(np.sum(a,axis=1))
print(np.max(a))
print(np.max(a,axis=0))
print(np.min(a))
'''
'''
import numpy as np

A = np.arange(14,2,-1).reshape((3,4))

print(A)


print(np.argmax(A))
print(np.argmin(A))
print(np.mean(A))
print(np.average(A))
print(np.median(A))
print(np.cumsum(A))
print(np.nonzero(A))
print(np.sort(A))
print(A.T)
print((A.T).dot(A))
print(np.clip(A,4,10))
#print(A.average())
'''
'''
import numpy as np

A = np.arange(3,15).reshape((3,4))

print(A)
print(A[2][1])
print(A[2,1])
print(A[2,:])
print(A[:,1])
print(A[1,1:3])

for row in A:
    print(row)

for column in A.T:
    print(column)

print(A.flatten())

for item in A.flat:
    print(item)
'''
'''
import numpy as np

A = np.array([1,1,1])
B = np.array([2,2,2])

C = np.vstack((A,B)) # 竖直合并
D = np.hstack((A,B)) # 水平合并

print(A.shape)
print(C)
print(C.shape)
print(D)
print(D.shape)

print(A[np.newaxis,:])
print(A[np.newaxis,:].shape)
print(A[:,np.newaxis])
print(A[:,np.newaxis].shape)


A = np.array([1,1,1])[:,np.newaxis]
B = np.array([2,2,2])[:,np.newaxis]

print(A)
print(B)
print(np.hstack((A,B,B)))

C = np.concatenate((A,B,B,A),axis=0)
print(C)

C = np.concatenate((A,B,B,A),axis=1)
print(C)
'''
'''
import numpy as np

A = np.arange(12).reshape((3,4))

print(A)

print(np.split(A,2,axis=1))

print(np.split(A,3,axis=0))

print(np.array_split(A,3,axis=1))

print(np.vsplit(A,3))
print(np.hsplit(A,2))
'''

'''
import pandas as pd
import numpy as np

dates = pd.date_range('20130101',periods=6)
df = pd.DataFrame(np.arange(24).reshape((6,4)),index=dates,columns=['A','B','C','D'])

print(df)
print(df['A'])
print(df.A)
print(df[0:3])
print(df['20130102':'20130104'])

print(df.loc['20130102'])
print(df.loc[:,['A','B']])
print(df.loc['20130101',['A','B']])

print(df.iloc[3:5,1:3])
print(df.iloc[[1,3,5],1:3])

print(df[df.A>8])
'''
'''
import pandas as pd
import numpy as np

dates = pd.date_range('20130101',periods=6)
df = pd.DataFrame(np.arange(24).reshape((6,4)),index=dates,columns=['A','B','C','D'])

print(df)

df.iloc[2,2] = 1111
print(df)

df.loc['20130101','B'] = 2222
print(df)

df.B[df.A>4] = 0 # index A > 4 的  B列 值 全赋值为0
print(df)

df[df.A>4] = 0 # index A > 4 下的这几行,全部赋值为0向量
print(df)

df['F'] = np.nan
print(df)

df['E'] = pd.Series([1,2,3,4,5,6],index=pd.date_range('20130101',periods=6))
print(df)
'''
'''
import pandas as pd
import numpy as np

dates = pd.date_range('20130101',periods=6)
df = pd.DataFrame(np.arange(24).reshape((6,4)),index=dates,columns=['A','B','C','D'])

df.iloc[0,1] = np.nan
df.iloc[1,2] = np.nan
print(df)

print(df.isnull()) # 判断每个位置是否缺失数据

print(np.any(df.isnull()))
print(np.any(df.isnull()) == True) # 判断是否缺失数据

print(df.fillna(value=0)) # 将nan填为0

print(df.dropna(axis=0,how='any')) # how = {'any','all'} any代表有一个nan，则丢掉整行；all代表全为nan则丢掉整行；默认how为any
'''
'''
import pandas as pd

data = pd.read_csv('student.csv')

print(data)

data.to_pickle('student.pickle')
'''
'''
import pandas as pd
import numpy as np

# concatenating

df1 = pd.DataFrame(np.ones((3,4))*0,columns=['a','b','c','d'])
df2 = pd.DataFrame(np.ones((3,4))*1,columns=['a','b','c','d'])
df3 = pd.DataFrame(np.ones((3,4))*2,columns=['a','b','c','d'])

print(df1)
print(df2)
print(df3)

res = pd.concat([df1,df2,df3],axis=0,ignore_index=True) # 合并df1,df2,df3 以axis=0为单位方向 ignore_index 忽略行标重新设置
print(res)

#join,['inner','outer']
df4 = pd.DataFrame(np.ones((3,4))*0,columns=['a','b','c','d'],index=[1,2,3])
df5 = pd.DataFrame(np.ones((3,4))*1,columns=['b','c','d','e'],index=[2,3,4])

print(df4)
print(df5)

res1 = pd.concat([df4,df5],join='outer') # 默认join='outer'
res2 = pd.concat([df4,df5],join='inner')
res3 = pd.concat([df4,df5],join='inner',ignore_index=True)

print(res1)
print(res2)
print(res3)

#join_axes 新版本已删除

res4 = pd.concat([df4,df5],axis=1) # ,join_axes=[df4.index]
print(res4)

# append
s1 = pd.Series([1,2,3,4],index=['a','b','c','d'])
res = df1.append(s1,ignore_index=True)

print(res)
'''
'''
import pandas as pd

# merge to df by key/keys.(may be used in database)
# simple example
left = pd.DataFrame({'key':['K0','K1','K2','K3'],
                     'A':['A0','A1','A2','A3'],
                     'B':['B0','B2','B3','B4']})

right = pd.DataFrame({'key':['K0','K1','K2','K3'],
                     'C':['C0','C1','C2','C3'],
                     'D':['D0','D2','D3','D4']})

print(left)
print(right)

res = pd.merge(left,right,on='key') # 融合left,right 只有一个key column
print(res)
'''
'''
import pandas as pd

# merge to df by key/keys.(may be used in database)
# simple example
left = pd.DataFrame({'key1':['K0','K1','K2','K3'],
                     'key2':['K0','K1','K2','K3'],
                     'A':['A0','A1','A2','A3'],
                     'B':['B0','B2','B3','B4']})

right = pd.DataFrame({'key1':['K0','K1','K2','K3'],
                      'key2':['K0','K1','K2','K3'],
                     'C':['C0','C1','C2','C3'],
                     'D':['D0','D2','D3','D4']})

print(left)
print(right)

res = pd.merge(left,right,on=['key1','key2'],how='inner') # how = {'left','right','inner','outer'}
print(res)

'''
'''
import pandas as pd

df1 = pd.DataFrame({'col1': [0, 1], 'col_left': ['a', 'b']})
df2 = pd.DataFrame({'col1': [1, 2, 2], 'col_right': [2, 2, 2]})

print(df1)
print(df2)

res = pd.merge(df1,df2,on='col1',how='outer',indicator=True)
print(res)

# give the indicator a custom name

res = pd.merge(df1,df2,on='col1',how='outer',indicator='indicator_column')
print(res)
'''
'''
import pandas as pd

boys  = pd.DataFrame({'k':['K0','K1','K2'],'age':[1,2,3]})
girls = pd.DataFrame({'k':['K0','K1','K2'],'age':[4,5,6]})

print(boys)
print(girls)

res = pd.merge(boys,girls,on='k',suffixes=['_boys','_girls'],how='inner')

print(res)
'''
'''
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

# plot data

# Series
data = pd.Series(np.random.randn(1000),index=np.arange(1000))
data = data.cumsum()
data.plot()
plt.show()

data = pd.DataFrame(np.random.randn(1000,4),
                    index=np.arange(1000),
                    columns=list("ABCD"))

data = data.cumsum()

print(data.head()) # 默认打印前5个，也可以改为其他值

data.plot()
plt.show()

ax = data.plot.scatter(x='A',y='B',color='DarkBlue',label='Class 1')
data.plot.scatter(x='A',y='C',color='DarkGreen',label='Class 2',ax=ax)
plt.show()
'''
